Skip to content

Add Squid for Cosmos swaps#1015

Open
0xh3rman wants to merge 22 commits intomainfrom
squid
Open

Add Squid for Cosmos swaps#1015
0xh3rman wants to merge 22 commits intomainfrom
squid

Conversation

@0xh3rman
Copy link
Collaborator

No description provided.

Introduce a Cosmos signing implementation and protobuf-based tx encoding. Adds a new gem_cosmos signer module (chain_signer, protobuf, transaction) that can parse MsgExecuteContract and IBC MsgTransfer envelopes, build tx bodies/auth_info, and sign/encode transactions; includes unit tests and JSON testdata. Make the signer crate an optional feature of gem_cosmos and wire it into models and constants. Add low-level protobuf helpers, transaction encoding utilities, and expose secp256k1 public key helper from signer. Update primitives: add Cosmos denom mapping and extend SwapProvider with Squid; adjust preload gas estimation to account for non-Thorchain swap providers. Add serde_serializers for i32/u32 string-or-number deserialization and small SignerError/decoding error mappings and formatting helpers across signer/primitives for consistent error handling.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the platform's cross-chain swap capabilities by integrating Squid as a new swap provider. This integration allows users to perform swaps involving several Cosmos-based chains, such as Osmosis, Celestia, Injective, Sei, and Noble. The changes include the development of a dedicated Cosmos signer module to correctly encode and sign transactions for these new swap types, alongside adjustments to gas limit estimations to ensure smooth transaction processing.

Highlights

  • Squid Integration: Integrated Squid as a new cross-chain swap provider, enabling swaps across various Cosmos-based chains.
  • Cosmos Signer Module: Introduced a new signer module within gem_cosmos to handle Cosmos transaction signing, including protobuf encoding for MsgExecuteContract and MsgTransfer (IBC) messages.
  • Expanded Cosmos Chain Support: Extended Cosmos chain support to include Osmosis, Celestia, Injective, Sei, and Noble for Squid-powered swaps.
  • Dynamic Gas Limit Calculation: Updated gas limit calculation logic for swap transactions to differentiate between Thorchain and other swap providers, accommodating higher gas requirements for providers like Squid.
  • Serde Deserialization Utilities: Added new deserialization utilities for i32 and u32 types in the serde_serializers crate to handle various string and integer formats.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Cargo.lock
    • Added signer to the dependencies list.
  • crates/gem_cosmos/Cargo.toml
    • Added signer dependency with an optional feature.
    • Included signer and serde_json in the signer feature.
  • crates/gem_cosmos/src/constants.rs
    • Added constants for MESSAGE_EXECUTE_CONTRACT and MESSAGE_IBC_TRANSFER.
  • crates/gem_cosmos/src/lib.rs
    • Added a new signer module, conditionally compiled with the signer feature.
  • crates/gem_cosmos/src/models/contract.rs
    • Added ExecuteContractValue struct for deserializing contract execution messages.
  • crates/gem_cosmos/src/models/ibc.rs
    • Added IbcTransferValue struct for deserializing IBC transfer messages, including tests for timeout timestamp deserialization.
  • crates/gem_cosmos/src/models/message.rs
    • Imported new constants and structs for contract execution and IBC transfers.
    • Added MessageEnvelope struct and CosmosMessage enum with parsing logic for MsgExecuteContract and MsgTransfer.
  • crates/gem_cosmos/src/models/mod.rs
    • Exported new contract and ibc modules, conditionally compiled with the signer feature.
  • crates/gem_cosmos/src/provider/preload_mapper.rs
    • Imported SwapProvider from primitives.
    • Modified get_gas_limit function to use chain parameter.
    • Updated gas limit calculation for TransactionInputType::Swap to apply different limits based on the SwapProvider.
  • crates/gem_cosmos/src/signer/chain_signer.rs
    • Added CosmosChainSigner struct and implemented the ChainSigner trait for Cosmos transactions.
    • Implemented encode_and_sign_tx for signing Cosmos transactions using Secp256k1.
  • crates/gem_cosmos/src/signer/mod.rs
    • Added new modules chain_signer, protobuf, and transaction.
    • Exported CosmosChainSigner.
  • crates/gem_cosmos/src/signer/protobuf.rs
    • Added utility functions for protobuf encoding of varints, bytes, strings, messages, and coins.
  • crates/gem_cosmos/src/signer/transaction.rs
    • Implemented type_url and encode_value methods for CosmosMessage.
    • Added functions for encoding Cosmos transaction components like tx_body, pubkey_any, mode_info_single, signer_info, fee, auth_info, sign_doc, and tx_raw.
  • crates/gem_cosmos/testdata/swap_execute_contract.json
    • Added test data for a MsgExecuteContract message.
  • crates/gem_cosmos/testdata/swap_ibc_transfer.json
    • Added test data for an MsgTransfer (IBC) message.
  • crates/primitives/src/chain_cosmos.rs
    • Added a denom method to the CosmosChain enum to return the native denomination for each chain.
  • crates/primitives/src/signer_error.rs
    • Implemented From<&str> and From<String> for SignerError to simplify error conversion.
  • crates/primitives/src/swap_provider.rs
    • Added Squid to the SwapProvider enum.
    • Updated is_cross_chain method to include Squid as a cross-chain provider.
    • Updated name method to return "Squid" for SwapProvider::Squid.
    • Updated priority method to assign Squid a priority of 2.
  • crates/serde_serializers/src/i32.rs
    • Added i32 deserialization logic from strings or integers, including hex support.
  • crates/serde_serializers/src/lib.rs
    • Exported new i32 and u32 deserialization modules.
  • crates/serde_serializers/src/u32.rs
    • Added u32 deserialization logic from strings or integers, including hex support.
  • crates/signer/src/eip712/mod.rs
    • Updated from_hex calls to use unwrap() instead of expect() for consistency.
  • crates/signer/src/lib.rs
    • Exported public_key_from_private from the secp256k1 module.
  • crates/signer/src/secp256k1.rs
    • Changed error type for SecpSigningKey::from_slice to SignerError::signing_error.
    • Added public_key_from_private function to derive a public key from a private key.
  • crates/swapper/src/models.rs
    • Added Squid to the SwapProviderMode::CrossChain mapping.
  • crates/swapper/src/proxy/mod.rs
    • Added a new squid module.
  • crates/swapper/src/proxy/provider.rs
    • Imported squid module and its constants.
    • Added new_squid constructor for ProxyProvider to support Cosmos chains.
    • Implemented get_transaction_status for Squid provider to retrieve swap status.
    • Implemented get_vault_addresses for Squid provider, returning the SQUID_COSMOS_MULTICALL address.
  • crates/swapper/src/proxy/provider_factory.rs
    • Added new_squid function to create a new Squid ProxyProvider.
  • crates/swapper/src/proxy/squid/client.rs
    • Added SquidClient for making API requests to the Squid service to get transaction status.
  • crates/swapper/src/proxy/squid/mod.rs
    • Added client and model modules.
    • Exported SquidClient and defined SQUID_COSMOS_MULTICALL constant.
  • crates/swapper/src/proxy/squid/model.rs
    • Added SquidTransactionStatus and SquidStatus enums for deserializing Squid API responses.
    • Implemented swap_status method for SquidStatus to map to generic SwapStatus.
  • crates/swapper/src/swapper.rs
    • Registered the new Squid swap provider in the GemSwapper initialization.
  • gemstone/Cargo.toml
    • Enabled the signer feature for the gem_cosmos dependency.
  • gemstone/src/block_explorer/mod.rs
    • Included Squid in the block explorer mapping, defaulting to a generic explorer.
  • gemstone/src/gem_swapper/remote_types.rs
    • Added Squid to the SwapperProvider enum for remote type definitions.
  • gemstone/src/signer/chain.rs
    • Imported CosmosChainSigner.
    • Mapped Cosmos, Osmosis, Celestia, Injective, Sei, and Noble chains to use the CosmosChainSigner.
Activity
  • The pull request description is empty, indicating that the changes are self-explanatory or were discussed out-of-band.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for Squid swaps on Cosmos chains. It introduces a new signer feature in gem_cosmos to handle transaction signing for MsgExecuteContract and MsgTransfer messages, including a manual protobuf implementation for encoding. The changes are well-structured and include necessary updates to providers and models. My review focuses on improving error handling, performance of the protobuf encoding, and correctness of swap status mapping.

@0xh3rman 0xh3rman requested a review from gemcoder21 March 19, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants